package com.midou.administration.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.midou.administration.entity.ServiceMessage;
import com.midou.administration.mapper.ServiceMessageMapper;
import com.midou.administration.service.ServiceMessageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ServiceMessageServiceImpl implements ServiceMessageService {
    @Resource
    private ServiceMessageMapper serviceMessageMapper;
    public Integer insertMessage(ServiceMessage sm){
        return serviceMessageMapper.addServiceMessage(sm);
    }
    public List<ServiceMessage> queryMessage(Integer bid){
        QueryWrapper qw = new QueryWrapper();
        qw.eq("bu_id",bid);
        qw.orderByDesc("sm_datetime");
        return serviceMessageMapper.selectList(qw);
    }
    public Integer queryCount(Integer bid,Integer state){
        QueryWrapper qw = new QueryWrapper();
        qw.eq("bu_id",bid);
        qw.eq("sm_if_deal_with",state);
        return serviceMessageMapper.selectCount(qw);
    }

    @Override
    public Integer modifyMessageState(ServiceMessage sm) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("sm_id",sm.getSmId());
        return serviceMessageMapper.update(sm,queryWrapper);
    }
}
